]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
backgroundMenu: Add a context menu on the background actor
authorJasper St. Pierre <jstpierre@mecheye.net>
Fri, 21 Dec 2012 12:55:00 +0000 (07:55 -0500)
committerJasper St. Pierre <jstpierre@mecheye.net>
Mon, 18 Feb 2013 20:23:25 +0000 (15:23 -0500)
Allow users to change their wallpaper and launch System Settings
from it.

https://bugzilla.gnome.org/show_bug.cgi?id=681540

data/theme/gnome-shell.css
js/Makefile.am
js/ui/backgroundMenu.js [new file with mode: 0644]
js/ui/main.js

index 0e174f2753164ecbc49fab7606bbb050a4ad8932..c06ed563e727a8ba8f3d52cc17666b14ab0458d6 100644 (file)
@@ -2481,3 +2481,9 @@ StScrollBar StButton#vhandle:active {
    width: 96px;
    height: 96px;
 }
+
+/* Background menu */
+
+.background-menu {
+    -boxpointer-gap: 4px;
+}
index df389b8252a88875be4f2dda8fbf191d51af3925..b6fcea7332f2ad89f04d150e00b847eb43ab8363 100644 (file)
@@ -39,6 +39,7 @@ nobase_dist_js_DATA =         \
        ui/altTab.js            \
        ui/appDisplay.js        \
        ui/appFavorites.js      \
+       ui/backgroundMenu.js    \
        ui/boxpointer.js        \
        ui/calendar.js          \
        ui/checkBox.js          \
diff --git a/js/ui/backgroundMenu.js b/js/ui/backgroundMenu.js
new file mode 100644 (file)
index 0000000..138af05
--- /dev/null
@@ -0,0 +1,57 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const Clutter = imports.gi.Clutter;
+const Lang = imports.lang;
+const St = imports.gi.St;
+const Shell = imports.gi.Shell;
+
+const BoxPointer = imports.ui.boxpointer;
+const Main = imports.ui.main;
+const PopupMenu = imports.ui.popupMenu;
+
+const BackgroundMenu = new Lang.Class({
+    Name: 'BackgroundMenu',
+    Extends: PopupMenu.PopupMenu,
+
+    _init: function(source) {
+        this.parent(source, 0, St.Side.TOP);
+
+        this.addSettingsAction(_("Change Wallpaper..."), 'gnome-background-panel.desktop');
+        this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
+        this.addSettingsAction(_("System Settings"), 'gnome-control-center.desktop');
+
+        this.actor.add_style_class_name('background-menu');
+
+        Main.uiGroup.add_actor(this.actor);
+        this.actor.hide();
+    }
+});
+
+function addBackgroundMenu(actor) {
+    let cursor = new St.Bin({ opacity: 0 });
+    Main.uiGroup.add_actor(cursor);
+
+    actor._backgroundMenu = new BackgroundMenu(cursor);
+    actor._backgroundManager = new PopupMenu.PopupMenuManager({ actor: actor });
+    actor._backgroundManager.addMenu(actor._backgroundMenu);
+
+    function openMenu() {
+        let [x, y] = global.get_pointer();
+        cursor.set_position(x, y);
+        actor._backgroundMenu.open(BoxPointer.PopupAnimation.FULL);
+    }
+
+    let clickAction = new Clutter.ClickAction();
+    clickAction.connect('long-press', function(action, actor, state) {
+        if (state == Clutter.LongPressState.QUERY)
+            return action.get_button() == 1 && !actor._backgroundMenu.isOpen;
+        if (state == Clutter.LongPressState.ACTIVATE)
+            openMenu();
+        return true;
+    });
+    clickAction.connect('clicked', function(action) {
+        if (action.get_button() == 3)
+            openMenu();
+    });
+    actor.add_action(clickAction);
+}
index ae0754a0827cc392cba83a61daa3ac0b8cf958d6..68cd4499aaae52b3c214645426578adbb5bb3a1b 100644 (file)
@@ -10,6 +10,7 @@ const Meta = imports.gi.Meta;
 const Shell = imports.gi.Shell;
 const St = imports.gi.St;
 
+const BackgroundMenu = imports.ui.backgroundMenu;
 const Components = imports.ui.components;
 const CtrlAltTab = imports.ui.ctrlAltTab;
 const EndSessionDialog = imports.ui.endSessionDialog;
@@ -141,6 +142,8 @@ function start() {
     windowAttentionHandler = new WindowAttentionHandler.WindowAttentionHandler();
     componentManager = new Components.ComponentManager();
 
+    BackgroundMenu.addBackgroundMenu(global.background_actor);
+
     layoutManager.init();
     overview.init();